<template>
  <div class="goods-list">
    <div v-for="item in goodList" :key="item.id" class="good-items" @click="todetail(item.id)">
      <img :src="item.img_url" alt>
      <div class="tit">{{item.title}}</div>
      <div class="info">
        <div class="price">
          <span class="new">{{item.sell_price}}</span>
          <span class="old">{{item.market_price}}</span>
        </div>
        <div class="sell">
          <span>热卖中</span>
          <span>剩8件</span>
        </div>
      </div>
    </div>
    <mt-button type="danger" size="large" @click="getmore()">加载更多</mt-button>
  </div>
</template>
<script>
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      goodList: [],
      pageindex: 1
    };
  },
  created() {
    this.getgoodslist();
  },
  methods: {
    getgoodslist() {
      this.$http
        .get("api/getgoods?pageindex=" + this.pageindex)
        .then(result => {
          if (result.body.status == 0) {
            this.goodList = this.goodList.concat(result.body.message);
          } else {
            Toast("获取失败");
            return;
          }
        });
    },
    getmore() {
      this.pageindex++;
      this.getgoodslist();
    },
    todetail(id) {
      this.$router.push({ name: "goodsinfo", params: { id } });
    }
  }
};
</script>
<style lang="scss" scope>
.goods-list {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 10px 10px;
  padding-bottom: 50px;
  .good-items {
    box-shadow: 2px 2px 8px #ccc;
    overflow: hidden;
    width: 48%;
    margin-bottom: 10px;
    .tit {
      font-size: 14px;
      color: #666;
      margin-bottom: 10px;
      margin-left: 10px;
    }
    .info {
      background: #eee;
      padding: 10px;
    }
    img {
      width: 100%;
    }
    .price .new {
      color: #f40;
      font-size: 14px;
    }
    .price .old {
      font-size: 12px;
      text-decoration: line-through;
      padding-left: 10px;
    }
    .sell {
      font-size: 12px;
      color: #333;
      display: flex;
      justify-content: space-between;
    }
  }
}
</style>
